﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using EntityObject;
using System.Data.OleDb;
using SharedLibraries;
using ThangNM_LIB.FUNC;
using ThangNM_LIB.EO;

namespace DataAccessObject
{
    public class QuestionAnswerDAO : DB_SQL_EXT
    {
        public Boolean Insert(QuestionAnswerEO _QuestionAnswerEO, SEOEO _SEOEO)
        {
            SqlCommand cmd = new SqlCommand("QuestionAnswer_Insert");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@FK_iAnswerID", _QuestionAnswerEO.FK_iAnswerID));
            cmd.Parameters.Add(new SqlParameter("@FK_iAccountID", _QuestionAnswerEO.FK_iAccountID));
            cmd.Parameters.Add(new SqlParameter("@sName", _QuestionAnswerEO.sName));
            cmd.Parameters.Add(new SqlParameter("@sEmail", _QuestionAnswerEO.sEmail));
            cmd.Parameters.Add(new SqlParameter("@sQuestionAnswerEx", _QuestionAnswerEO.sQuestionAnswerEx));
            cmd.Parameters.Add(new SqlParameter("@sTitle", _QuestionAnswerEO.sTitle));
            cmd.Parameters.Add(new SqlParameter("@sContent", _QuestionAnswerEO.sContent));
            cmd.Parameters.Add(new SqlParameter("@iVisit", _QuestionAnswerEO.iVisit));
            cmd.Parameters.Add(new SqlParameter("@iLike", _QuestionAnswerEO.iLike));
            cmd.Parameters.Add(new SqlParameter("@bNotification", _QuestionAnswerEO.bNotification));
            cmd.Parameters.Add(new SqlParameter("@iStatus", _QuestionAnswerEO.iStatus));
            //Insert tblSitemap
            cmd.Parameters.Add(new SqlParameter("@sUrlRewrite", NullEx.getNullValue(_SEOEO.sUrlRewrite)));
            cmd.Parameters.Add(new SqlParameter("@iChangefreq", NullEx.getNullValue(_SEOEO.iChangefreq)));
            cmd.Parameters.Add(new SqlParameter("@fPriority", _SEOEO.fPriority));
            //cmd.Parameters.Add(new SqlParameter("@iType", NullEx.getNullValue(_SEOEO.iType)));
            cmd.Parameters.Add(new SqlParameter("@bstatus", _SEOEO.bStatus));
            return ExecuteNonQuery_RetBool(cmd);
        }

        public  Boolean Update(QuestionAnswerEO _QuestionAnswerEO, SEOEO _SEOEO)
        {
            SqlCommand cmd = new SqlCommand("QuestionAnswer_Update");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@PK_iQuestionID", _QuestionAnswerEO.PK_iQuestionID));
            cmd.Parameters.Add(new SqlParameter("@sName", _QuestionAnswerEO.sName));
            cmd.Parameters.Add(new SqlParameter("@sEmail", _QuestionAnswerEO.sEmail));
            cmd.Parameters.Add(new SqlParameter("@sQuestionAnswerEx", _QuestionAnswerEO.sQuestionAnswerEx));
            cmd.Parameters.Add(new SqlParameter("@sTitle", _QuestionAnswerEO.sTitle));
            cmd.Parameters.Add(new SqlParameter("@sContent", _QuestionAnswerEO.sContent));
            cmd.Parameters.Add(new SqlParameter("@bNotification", _QuestionAnswerEO.bNotification));
            cmd.Parameters.Add(new SqlParameter("@iStatus", _QuestionAnswerEO.iStatus));
            //Insert tblSitemap
            cmd.Parameters.Add(new SqlParameter("@sUrlRewrite", NullEx.getNullValue(_SEOEO.sUrlRewrite)));
            cmd.Parameters.Add(new SqlParameter("@iChangefreq", NullEx.getNullValue(_SEOEO.iChangefreq)));
            cmd.Parameters.Add(new SqlParameter("@fPriority", _SEOEO.fPriority));
            //cmd.Parameters.Add(new SqlParameter("@iType", NullEx.getNullValue(_SEOEO.iType)));
            cmd.Parameters.Add(new SqlParameter("@bstatus", _SEOEO.bStatus));
            return ExecuteNonQuery_RetBool(cmd);
        }

        public  Boolean Update_bNotification_Or_iLike(QuestionAnswerEO _QuestionAnswerEO)
        {
            SqlCommand cmd = new SqlCommand("QuestionAnswer_Update_bNotification_Or_iLike");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@PK_iQuestionID", _QuestionAnswerEO.PK_iQuestionID));
            cmd.Parameters.Add(new SqlParameter("@iLike", NullEx.getNullValue(_QuestionAnswerEO.iLike)));
            cmd.Parameters.Add(new SqlParameter("@sEmail", _QuestionAnswerEO.sEmail));
            cmd.Parameters.Add(new SqlParameter("@bNotification", _QuestionAnswerEO.bNotification));
            return ExecuteNonQuery_RetBool(cmd);
        }

        public  Boolean Delete(string _PK_iQuestionAnswerID, String _loc_old)
        {
            SqlCommand cmd = new SqlCommand("QuestionAnswer_Delete");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@PK_iQuestionID", _PK_iQuestionAnswerID));
            cmd.Parameters.Add(new SqlParameter("@loc_old", _loc_old));
            return ExecuteNonQuery_RetBool(cmd);
        }

        public  DataSet SelectBy_PK_iQuestionID(Int32 _PK_iQuestionID)
        {
            SqlCommand cmd = new SqlCommand("QuestionAnswer_SelectBy_PK_iQuestionID");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@PK_iQuestionID", _PK_iQuestionID));
            return GetDataSet(cmd);
        }

        public  DataTable SelectBy_FK_iAnswerID_iStatus(Int32 _FK_iAnswerID, Int16 _iStatus)
        {
            SqlCommand cmd = new SqlCommand("QuestionAnswer_SelectBy_FK_iAnswerID_iStatus");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@FK_iAnswerID", _FK_iAnswerID));
            cmd.Parameters.Add(new SqlParameter("@iStatus", NullEx.getNullValue(_iStatus)));
            return GetDataTable(cmd);
        }

        public  QuestionAnswerEO SelectItem(Int32 _PK_iQuestionID)
        {
            SqlCommand cmd = new SqlCommand("QuestionAnswer_SelectItem");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@PK_iQuestionID", _PK_iQuestionID));
            return QuestionAnswerDO(GetDataTable(cmd));
        }

        public QuestionAnswerEO QuestionAnswerDO(DataTable input)
        {
            List<QuestionAnswerEO> lst = new List<QuestionAnswerEO>();
            lst = (List<QuestionAnswerEO>)ConvertEx.ConvertDataTableToListObject<QuestionAnswerEO>(input, lst.GetType());
            if (CommonsCheck.ListObject_OK(lst))
                return lst[0];
            else
                return null;
        }
    }
}